package com.wanghlme.leetcodecn;

/**
 * <p>剑指 Offer 24. 反转链表</p>
 * <p>JZ24->main0206</p>
 *
 * @author wanghlme
 * @version 1.0
 */
public class LC_JZ24 {
    public static void main(String[] args) {

    }

    public class ListNode {
        int val;
        ListNode next;

        ListNode(int x) {
            val = x;
        }
    }

    class Solution {
        public ListNode reverseList(ListNode head) {
            return reverse(null, head);
        }

        private ListNode reverse(ListNode pre, ListNode cur) {
            if (cur == null) return pre;
            ListNode tmp = cur.next;
            cur.next = pre;
            return reverse(cur, tmp);
        }
    }
}
